package com.soilflow.common.utils.easyexcel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * 0在职党员，1离（退）休干部、职工党员，2农名、学生、失业党员党费
 * @author chengshihua
 */
public class MemberTypeConverter implements Converter<Short> {

    //在java中默认是用 0 1 来标识的  所以是int
    @Override
    public Class supportJavaTypeKey() {return Short.class;}

    // 在excel中是默认非默认 所以是string
    @Override
    public CellDataTypeEnum supportExcelTypeKey() {return CellDataTypeEnum.STRING;}
 
    //将excel的数据类型转为java数据类型
    @Override
    public Short convertToJavaData(ReadCellData readCellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String stringValue = readCellData.getStringValue();
        if (stringValue == null) {
            return null;
        }
        if ("在职党员".equals(stringValue)) {
            return 0;
        }
        if ("离（退）休干部、职工党员".equals(stringValue)){
            return 1;
        }
        if ("农名、学生、失业党员党费".equals(stringValue)){
            return 2;
        }
        return null;
    }
 
    //将java的数据类型转为excel数据类型
    @Override
    public WriteCellData convertToExcelData(Short s, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if	(s==0){
            return new WriteCellData("在职党员");
        }
        if	(s==1){
            return new WriteCellData("离（退）休干部、职工党员");
        }
        if	(s==2){
            return new WriteCellData("农名、学生、失业党员党费");
        }
        return new WriteCellData("");
    }
}